package com.project.scheduled.controller;

import com.project.scheduled.service.BusinessLogicService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 手工执行定时任务
 */
@Slf4j
@RestController
@RequestMapping("/businessLogic")
public class BusinessLogicController {
    @Resource
    private BusinessLogicService businessLogicService;

    private  static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5,10,200,
            TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>(2000));

    @GetMapping("/health")
    public String health() {
        Runtime runtime = Runtime.getRuntime();
        long usedMemory = runtime.totalMemory() - runtime.freeMemory();
        return String.format("Used Memory: %d MB", usedMemory / 1024 / 1024);
    }

    /**
     * 线路时刻表每日作业数据
     */
    @RequestMapping("/xlskbStartDay")
    public void xlskbStartDay() {
        threadPoolExecutor.execute(()->{businessLogicService.xlskbStartDay();});
    }

    /**
     * insert_get_user_czcl_liv
     */
    @RequestMapping("/insert_get_user_czcl_liv")
    public void insert_get_user_czcl_liv() {
        threadPoolExecutor.execute(()->{businessLogicService.insert_get_user_czcl_liv();});
    }

    /**
     * pro_update_xlskb_extend
     */
    @RequestMapping("/pro_update_xlskb_extend")
    public void pro_update_xlskb_extend() {
        threadPoolExecutor.execute(()->{businessLogicService.pro_Update_XLSKB_EXTEND();});
    }

    /**
     * insert_tb_training_certificate_uid_liv
     */
    @RequestMapping("/insert_tb_training_certificate_uid_liv")
    public void insert_tb_training_certificate_uid_liv() {
        threadPoolExecutor.execute(()->{businessLogicService.insert_TB_TRAINING_CERTIFICATE_UID_LIV();});
    }


    /**
     * pro_insert_tb_czcl_rfid_day
     */
    @RequestMapping("/pro_insert_tb_czcl_rfid_day")
    public void pro_insert_tb_czcl_rfid_day() {
        threadPoolExecutor.execute(()->{businessLogicService.pro_insert_TB_CZCL_RFID_DAY();});
    }

    /**
     * pro_insert_tb_czcl_rfid_day
     */
    @RequestMapping("/pro_insert_tb_czxl_rfid_day")
    public void pro_insert_tb_czxl_rfid_day() {
        threadPoolExecutor.execute(()->{businessLogicService.pro_insert_TB_CZXL_RFID_DAY();});
    }
    /**
     * backupZdTable
     */
    @RequestMapping("/backupZdTable")
    public void backupZdTable() {
        threadPoolExecutor.execute(()->{businessLogicService.backupZdTable();});
    }


    /**
     * backupClwzDay
     */
    @RequestMapping("/backupClwzDay")
    public void backupClwzDay() {
        threadPoolExecutor.execute(()->{businessLogicService.backup_clwz_day();});
    }

    /**
     * backupClwzTmp
     */
    @RequestMapping("/backupClwzTmp")
    public void backupClwzTmp() {
        threadPoolExecutor.execute(()->{businessLogicService.backup_clwz_tmp();});
    }

    /**
     * cleanRawMsg
     */
    @RequestMapping("/cleanRawMsg")
    public void cleanRawMsg() {
        threadPoolExecutor.execute(()->{businessLogicService.cleanRawMsg();});
    }

}
